﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MongoDB.Driver;
using System.Data;

namespace DataAccessService.IService
{
    public interface IMongoDBService
    {
        /// <summary>
        /// 获取连接
        /// </summary>
        /// <returns></returns>
        MongoDatabase GetConn();

        /// <summary>
        /// 根据sql查询获取实体
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sql"></param>
        /// <returns></returns>
        List<T> QueryList<T>(string sql);

        /// <summary>
        /// 根据条件查询
        /// </summary>
        /// <typeparam name="T">实体类型</typeparam>
        /// <param name="whereClause">查询条件(例如:name='张三')</param>
        /// <returns></returns>
        List<T> GetList<T>(string whereClause);

        /// <summary>
        /// 请求任意sql
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        DataSet QuerySQL(string sql);

        /// <summary>
        /// 执行任意sql
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        bool ExcuteSql(string sql);

        /// <summary>
        /// 新增数据
        /// </summary>
        /// <typeparam name="T">实体类型</typeparam>
        /// <param name="item">实体</param>
        /// <returns></returns>
        bool AddItem<T>(T item, string idField);

        /// <summary>
        /// 批量新增数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="items"></param>
        /// <param name="idField"></param>
        /// <returns></returns>
        bool AddItems<T>(List<T> items, string idField);

        /// <summary>
        /// 编辑数据
        /// </summary>
        /// <typeparam name="T">实体类型</typeparam>
        /// <param name="idField">id字段</param>
        /// <param name="item">实体</param>
        /// <param name="id">数据id</param>
        /// <returns></returns>
        bool UpdateItem<T>(T item, string idField, string id);

        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="whereClause"></param>
        /// <returns></returns>
        bool DeleteItem(string tableName, string whereClause);

        /// <summary>
        /// 结果转换为实体
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="dataSet"></param>
        /// <returns></returns>
        List<T> ConvertDataSetToEntity<T>(DataSet dataSet);
    }
}
